package org.amphiprion.montrictracv4.fragment;

import org.amphiprion.montrictracv4.MainActivity;
import org.amphiprion.montrictracv4.R;

import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

public class MenuFragment extends SherlockFragment implements View.OnClickListener {
	private View fragment;
	public static MenuFragment sThis;
	private LayoutInflater mInflater;
	private ListView mListView;

	private ActionMode.Callback mActionModeCallback;
	private ActionMode mActionMode;

	private void initLayout() {
		// this.mListView = ((ListView) this.fragment.findViewById(R.id.gameSessionList));
		// this.mListView.setEmptyView(this.fragment.findViewById(android.R.id.empty));
		TextView txtVersion = (TextView) this.fragment.findViewById(R.id.txtVersion);
		try {
			txtVersion.setText("v" + getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName);
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		mActionModeCallback = new ActionMode.Callback() {

			@Override
			public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
				return false;
			}

			@Override
			public void onDestroyActionMode(ActionMode mode) {
				mActionMode = null;
			}

			@Override
			public boolean onCreateActionMode(ActionMode mode, Menu menu) {
				// MenuInflater inflater = mode.getMenuInflater();
				// inflater.inflate(R.menu.context_game_session, menu);
				return true;
			}

			@Override
			public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
				// switch (item.getItemId()) {
				// case R.id.edit:
				// mode.finish(); // Action picked, so close the CAB
				// MainActivity.sThis.onAddEditGameSession(current);
				// // shareCurrentItem();
				// return true;
				// default:
				// return false;
				// }
				return true;
			}
		};
	}

	public static MenuFragment newInstance() {
		return new MenuFragment();
	}

	@Override
	public void onActivityCreated(Bundle paramBundle) {
		super.onActivityCreated(paramBundle);
		initLayout();
	}

	@Override
	public void onClick(View paramView) {
		// switch (paramView.getId()) {
		// case R.id.edit:
		// toggleEdit();
		// return;
		// }

	}

	@Override
	public void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		sThis = this;
	}

	@Override
	public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
		super.onCreateView(paramLayoutInflater, paramViewGroup, paramBundle);
		this.mInflater = paramLayoutInflater;
		this.fragment = this.mInflater.inflate(R.layout.fragment_sliding_menu, paramViewGroup, false);
		View vLudoList = fragment.findViewById(R.id.btMenuLudoList);
		vLudoList.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				MainActivity.sThis.toggle();
				MainActivity.sThis.showLudothequeList();
			}
		});

		View vSearchList = fragment.findViewById(R.id.btMenuSearchList);
		vSearchList.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				MainActivity.sThis.toggle();
				MainActivity.sThis.showSearchList();

			}
		});

		return this.fragment;
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		sThis = null;
	}

	@Override
	public void onResume() {
		super.onResume();
	}

}